<?php

class SRate_3d
{

    public $disk = "a";
    public $lotto_id = 0;
    public $table_name = NULL;
    public $table_nameNum = NULL;
    public $db = NULL;
    public $diskStrArr = array
        (
        1 => "a" ,
        2 => "b" ,
        3 => "c" ,
        4 => "d"
    );
    public $diskStrArrB = array
        (
        1 => "A 盘" ,
        2 => "B 盘" ,
        3 => "C 盘" ,
        4 => "D 盘"
    );
    public $tbl = NULL;
    public $gametype = NULL;
    public $betForNumTbl = array
        (
        13 => array
            (
            "r01" => 0 ,
            "r02" => 2
        ) ,
        14 => array
            (
            "r01" => 0 ,
            "r02" => 2
        ) ,
        15 => array
            (
            "r01" => 0 ,
            "r02" => 2
        ) ,
        16 => array
            (
            "r01" => 0 ,
            "r02" => 2
        ) ,
        20 => array
            (
            "r01" => 0 ,
            "r02" => 2 ,
            "r03" => 3
        ) ,
        21 => array
            (
            "r01" => 0 ,
            "r02" => 2 ,
            "r03" => 3
        ) ,
        35 => array
            (
            "r01" => 0 ,
            "r02" => 2 ,
            "r03" => 3
        )
    );
    public $betForNumDiffTbl = array
        (
        13 => array
            (
            1 => "r02" ,
            2 => "r01"
        ) ,
        14 => array
            (
            1 => "r02" ,
            2 => "r01"
        ) ,
        15 => array
            (
            1 => "r02" ,
            2 => "r01"
        ) ,
        16 => array
            (
            1 => "r02" ,
            2 => "r01"
        ) ,
        20 => array
            (
            1 => "r03" ,
            2 => "r02" ,
            3 => "r01"
        ) ,
        21 => array
            (
            1 => "r03" ,
            2 => "r02" ,
            3 => "r01"
        ) ,
        35 => array
            (
            1 => "r03" ,
            2 => "r02" ,
            3 => "r01"
        )
    );

    public function SRate_3d($gametype = 1 , $cid = -1)
    {
        global $g_gametype_3d;
        if ( 0 - 1 < $cid )
        {
            $this->db = new DB_CEN($cid);
        }
        else
        {
            $this->db = new DB();
        }
        $this->tbl = $g_gametype_3d[$gametype]['en'];
        $this->gametype = $gametype;
    }

    public function getRates($lotto_id_3d , $disk , $bettype , $subid = 0)
    {
        $sql = "!!SELECT r00, r01, r02, r03, r04, r05, r06, r07, r08, r09, r10, r11, r12, r13, r14, r15, r16, r17, r18, r19, r20, r21 FROM rate_{$this->tbl} WHERE bettype={$bettype} AND lotto_id={$lotto_id_3d} AND subid={$subid} AND disk={$disk} LIMIT 1";
		$result = $this->db->query($sql);
        return mysql_fetch_array($result , MYSQL_ASSOC);
    }

    public function getRatesNumArr($lotto_id_3d , $disk , $bettype , $subid = 0 , $numbers = -1)
    {
        $sql = "!!SELECT num, rate FROM ratenum_{$this->tbl} WHERE bettype={$bettype} AND lotto_id={$lotto_id_3d} AND subid={$subid} AND disk={$disk}";
        if ( is_array($numbers) )
        {
            $numbers = implode("," , $numbers);
        }
        if ( $numbers != 0 - 1 )
        {
            $sql .= " AND num in ({$numbers})";
        }
        $result = $this->db->query($sql);
        $numArr = array ( );
        while ( $row = mysql_fetch_array($result , MYSQL_ASSOC) )
        {
            $idx = $row['num'];
            $numArr[$idx] = $row['rate'];
        }
        return $numArr;
    }

    public function getRatesSNumArr($lotto_id_3d , $user_id , $bettype , $subid = 0 , $numbers = -1)
    {
        $sql = "!!SELECT num, rate FROM ratenums_{$this->tbl} WHERE bettype={$bettype} AND lotto_id={$lotto_id_3d} AND subid={$subid} AND user_id={$user_id}";
        if ( is_array($numbers) )
        {
            $numbers = implode("," , $numbers);
        }
        if ( $numbers != 0 - 1 )
        {
            $sql .= " AND num in ({$numbers})";
        }
        $result = $this->db->query($sql);
        $numArr = array ( );
        while ( $row = mysql_fetch_array($result , MYSQL_ASSOC) )
        {
            $idx = $row['num'];
            $numArr[$idx] = $row['rate'];
        }
        return $numArr;
    }

    public function getRatesS($lotto_id_3d , $bettype , $user_id , $subid = 0)
    {
        $sql = "!!SELECT r00, r01, r02, r03, r04, r05, r06, r07, r08, r09, r10, r11, r12, r13, r14, r15, r16, r17, r18, r19, r20, r21 FROM rates_{$this->tbl} WHERE bettype={$bettype} AND subid = {$subid} AND user_id={$user_id} AND lotto_id={$lotto_id_3d} LIMIT 1";
		$result = $this->db->query($sql);
        return mysql_fetch_array($result , MYSQL_ASSOC);
    }

    public function addRates($disk , $lotto_id , $bettype , $ratestr , $subIdArrVal = 0)
    {
        $sql = "INSERT INTO rate_{$this->tbl} (lotto_id,bettype,subid,disk)";
        $sql .= " VALUES('{$lotto_id}','{$bettype}','{$subIdArrVal}','{$disk}') ON DUPLICATE KEY UPDATE subid = {$subIdArrVal}";
        return $this->db->query($sql);
    }

    public function updateRate($lotto_id , $disk , $bettype , $ratedata , $subid = 0)
    {
        if ( count($ratedata) < 1 )
        {
            
        }
        else
        {
            $setArr = array ( );
            if ( 0 < $lotto_id )
            {
                foreach ( $ratedata as $key => $val )
                {
                    $setArr[] = "A.{$key} = IF({$val} > B.{$key}, B.{$key}, {$val})";
                }
                $setStr = implode("," , $setArr);
                $sql = "UPDATE rate_{$this->tbl} A LEFT JOIN rate_{$this->tbl} B ON (A.`bettype` = B.`bettype` AND A.`subid` = B.`subid` AND A.`disk` = B.`disk`) SET {$setStr} ";
                $sql .= " WHERE A.lotto_id = {$lotto_id} AND A.bettype = {$bettype} AND A.subid = {$subid} AND A.disk = {$disk} AND B.`lotto_id` = 0 ";
            }
            else
            {
                foreach ( $ratedata as $key => $val )
                {
                    $setArr[] = "{$key} = {$val}";
                }
                $setStr = implode("," , $setArr);
                $sql = "UPDATE rate_{$this->tbl} SET {$setStr} ";
                $sql .= " WHERE lotto_id = {$lotto_id} AND bettype = {$bettype} AND subid = {$subid} AND disk = {$disk}";
            }
            return $this->db->query($sql);
        }
    }

    public function updateNumRate($lotto_id , $disk , $bettype , $ratedata , $subid = 0)
    {
        if ( count($ratedata) < 1 )
        {
            return true;
        }
        if ( $lotto_id < 1 )
        {
            return true;
        }
        foreach ( $ratedata as $key => $val )
        {
            $sql = "INSERT INTO `ratenum_{$this->tbl}` (lotto_id,\tbettype, subid,\tdisk,\tnum, rate)";
            $sql .= " VALUES";
            $sql .= " ({$lotto_id},\t{$bettype}, {$subid},\t{$disk},\t{$key}, {$val})";
            $sql .= " ON DUPLICATE KEY UPDATE rate = {$val}";
            $this->db->query($sql);
        }
        return true;
    }

    public function updateRateByAddVal($lotto_id , $disk , $bettype , $ratedata , $subid = 0)
    {
        if ( count($ratedata) < 1 )
        {
            return false;
        }
        if ( $lotto_id < 1 )
        {
            return false;
        }
        if ( $disk == "-1" )
        {
            $diskStr = "";
        }
        else
        {
            $diskStr = " AND A.disk IN ({$disk})";
        }
        $setArr = array ( );
        foreach ( $ratedata as $key => $val )
        {
            $setArr[] = "A.{$key} = IF((A.{$key} + {$val}) > B.{$key}, B.{$key}, (A.{$key} + {$val}))";
        }
        if ( 0 < count($setArr) )
        {
            $setStr = implode("," , $setArr);
        }
        else
        {
            return false;
        }
        $sql = "UPDATE rate_{$this->tbl} A LEFT JOIN rate_{$this->tbl} B ";
        $sql .= " ON (A.`bettype` = B.`bettype` AND A.`subid` = B.`subid` AND A.`disk` = B.`disk`)";
        $sql .= " SET {$setStr}";
        $sql .= " WHERE A.lotto_id = {$lotto_id} AND A.bettype = {$bettype} AND A.subid = {$subid} {$diskStr} AND B.lotto_id = 0";
        return $this->db->query($sql);
    }

    public function updateRateSByAddVal($lotto_id , $user_id , $bettype , $ratedata , $subid = 0)
    {
        if ( count($ratedata) < 1 )
        {
            return false;
        }
        if ( $lotto_id < 1 )
        {
            return false;
        }
        $setArrF = array ( );
        $setArrV = array ( );
        $setArr = array ( );
        foreach ( $ratedata as $key => $val )
        {
            $setArrF[] = "{$key}";
            $setArrV[] = "{$val}";
            $setArr[] = "{$key} = {$key} + {$val}";
        }
        if ( 0 < count($setArr) )
        {
            $setStrF = implode("," , $setArrF);
            $setStrV = implode("," , $setArrV);
            $setStr = implode("," , $setArr);
        }
        else
        {
            return false;
        }
        $sql = "INSERT INTO rates_{$this->tbl} ";
        $sql .= " (lotto_id, bettype, subid, user_id, {$setStrF}) VALUES ({$lotto_id}, {$bettype}, {$subid}, {$user_id}, {$setStrV}) ";
        $sql .= " ON DUPLICATE KEY UPDATE {$setStr}";
        return $this->db->query($sql);
    }

    public function updateRateSByZeroVal($lotto_id , $user_id , $bettype , $ratedata , $subid = 0)
    {
        if ( count($ratedata) < 1 )
        {
            return false;
        }
        if ( $lotto_id < 1 )
        {
            return false;
        }
        $setArrF = array ( );
        $setArrV = array ( );
        $setArr = array ( );
        foreach ( $ratedata as $key => $val )
        {
            $setArrF[] = "{$key}";
            $setArrV[] = "0";
            $setArr[] = "{$key} = 0";
        }
        if ( 0 < count($setArr) )
        {
            $setStrF = implode("," , $setArrF);
            $setStrV = implode("," , $setArrV);
            $setStr = implode("," , $setArr);
        }
        else
        {
            return false;
        }
        $sql = "INSERT INTO rates_{$this->tbl} ";
        $sql .= " (lotto_id, bettype, subid, user_id, {$setStrF}) VALUES ({$lotto_id}, {$bettype}, {$subid}, {$user_id}, {$setStrV}) ";
        $sql .= " ON DUPLICATE KEY UPDATE {$setStr}";
        return $this->db->query($sql);
    }

    public function updateRateNumByAddVal($lotto_id , $disk , $bettype , $ratedata , $subid = 0)
    {
        if ( count($ratedata) < 1 )
        {
            return false;
        }
        if ( $lotto_id < 1 )
        {
            return false;
        }
        if ( $disk == "-1" )
        {
            $diskArr = array ( 1 , 2 , 3 , 4 );
        }
        else
        {
            $diskArr = explode("," , $disk);
        }
        $setArr = array ( );
        $sql = "SELECT r01, r02, r03, disk FROM rate_{$this->tbl} WHERE lotto_id = {$lotto_id} AND\tbettype = {$bettype} AND subid = {$subid} AND disk IN (".implode("," , $diskArr).") LIMIT 4";
        $rs = $this->db->query($sql);
        $diskRateArr = array ( array ( 0 , 0 , 0 ) , array ( 0 , 0 , 0 ) , array ( 0 , 0 , 0 ) , array ( 0 , 0 , 0 ) );
        while ( $row = mysql_fetch_row($rs) )
        {
            $diskRateArr[$row[3]] = $row;
        }
        $chkRateArr = $this->betForNumDiffTbl[$bettype];
        $numLen = count($chkRateArr);
        foreach ( $ratedata as $key => $val )
        {
            if ( $numLen == 2 )
            {
                if ( substr($key , 0 , 1) == substr($key , 1 , 1) )
                {
                    $rateChkIdx = 1;
                }
                else
                {
                    $rateChkIdx = 0;
                }
            }
            else if ( $numLen == 3 )
            {
                if ( substr($key , 0 , 1) == substr($key , 1 , 1) && substr($key , 0 , 1) == substr($key , 2 , 1) )
                {
                    $rateChkIdx = 2;
                }
                else
                {
                    if ( substr($key , 0 , 1) == substr($key , 1 , 1) || substr($key , 0 , 1) == substr($key , 2 , 1) || substr($key , 1 , 1) == substr($key , 2 , 1) )
                    {
                        $rateChkIdx = 1;
                    }
                    else
                    {
                        $rateChkIdx = 0;
                    }
                }
            }
            else
            {
                return false;
            }
            foreach ( $diskArr as $diskVal )
            {
                $rateChkVal = $diskRateArr[$diskVal][$rateChkIdx];
                $okVal = min($val , $rateChkVal);
                $sql = "INSERT INTO `ratenum_{$this->tbl}` (lotto_id,\tbettype, subid,\tdisk,\tnum, rate)";
                $sql .= " VALUES";
                $sql .= "({$lotto_id}, {$bettype}, {$subid},\t{$diskVal},\t'{$key}', {$okVal})";
                $sql .= " ON DUPLICATE KEY UPDATE rate = IF(rate + {$val} > {$rateChkVal}, {$rateChkVal}, rate + {$val})";
                $this->db->query($sql);
            }
        }
        return true;
    }

    public function updateRateSNumByAddVal($lotto_id , $user_id , $bettype , $ratedata , $subid = 0)
    {
        if ( count($ratedata) < 1 )
        {
            return false;
        }
        if ( $lotto_id < 1 )
        {
            return false;
        }
        $setArr = array ( );
        foreach ( $ratedata as $key => $val )
        {
            $sql = "INSERT INTO `ratenums_{$this->tbl}` (lotto_id,\tbettype, subid,\tuser_id,\tnum, rate)";
            $sql .= " VALUES";
            $sql .= " ({$lotto_id}, {$bettype}, {$subid},\t{$user_id},\t'{$key}', {$val})";
            $sql .= " ON DUPLICATE KEY UPDATE rate = rate + {$val}";
            $this->db->query($sql);
        }
        return true;
    }

    public function updateRateSNumByZeroVal($lotto_id , $user_id , $bettype , $ratedata , $subid = 0)
    {
        if ( count($ratedata) < 1 )
        {
            return false;
        }
        if ( $lotto_id < 1 )
        {
            return false;
        }
        $setArr = array ( );
        foreach ( $ratedata as $key => $val )
        {
            $sql = "INSERT INTO `ratenums_{$this->tbl}` (lotto_id,\tbettype, subid,\tuser_id,\tnum, rate)";
            $sql .= " VALUES";
            $sql .= " ({$lotto_id}, {$bettype}, {$subid},\t{$user_id},\t'{$key}', 0)";
            $sql .= " ON DUPLICATE KEY UPDATE rate = 0";
            $this->db->query($sql);
        }
        return true;
    }

    public function addRatesS($lotto_id , $user_id , $bettype , $ratestr , $subid = 0)
    {
        $sql = "INSERT INTO rates_{$this->tbl} (lotto_id,bettype,subid,user_id,ratedata,updatetime)";
        $sql .= " VALUES('{$lotto_id}','{$bettype}','{$subid}','{$user_id}','{$ratestr}','".systime()."')";
        return $this->db->query($sql);
    }

    public function updateRateS($lotto_id , $user_id , $bettype , $ratedata , $subid = 0)
    {
        $sql = "UPDATE rates_{$this->tbl} SET ratedata = '{$ratedata}', updatetime='".systime()."'";
        $sql .= " WHERE lotto_id = '{$lotto_id}' AND bettype = '{$bettype}' AND subid = '{$subid}' AND user_id = '{$user_id}'";
        return $this->db->query($sql);
    }

    public function getLotto3DByDate($day)
    {
        $sql = "SELECT * FROM lotto_{$this->tbl} WHERE open = '{$day}' limit 0,1";
        $result = $this->db->query($sql);
        return mysql_fetch_array($result , MYSQL_ASSOC);
    }

    public function getLotto3DById($id)
    {
        $sql = "SELECT * FROM lotto_{$this->tbl} WHERE id='{$id}' limit 0,1";
        $result = $this->db->query($sql);
        return mysql_fetch_array($result , MYSQL_ASSOC);
    }

    public function getLotto3DByIdNext($id)
    {
        $sql = "SELECT * FROM lotto_{$this->tbl} WHERE id > '{$id}' AND open != '0000-00-00' ORDER BY id ASC limit 0,1";
        $result = $this->db->query($sql);
        return mysql_fetch_array($result , MYSQL_ASSOC);
    }

    public function getLotto3DByIdPre($id)
    {
        $sql = "SELECT * FROM lotto_{$this->tbl} WHERE id < '{$id}' AND open != '0000-00-00' ORDER BY id DESC limit 0,1";
        $result = $this->db->query($sql);
        return mysql_fetch_array($result , MYSQL_ASSOC);
    }

    public function getAcl5ID($user_id , $acl)
    {
        $sql = "";
        switch ( $acl )
        {
            case 1 :
                $sql = "SELECT a.id FROM k_user a \r\n              LEFT JOIN k_user b ON a.id = b.prev_id \r\n              LEFT JOIN k_user c ON b.id = c.prev_id \r\n              LEFT JOIN k_user d ON c.id = d.prev_id\r\n              LEFT JOIN k_user e ON d.id = e.prev_id\r\n              WHERE e.id={$user_id} AND a.acl = 5";
                break;
            case 2 :
                $sql = "SELECT a.id FROM k_user a \r\n              LEFT JOIN k_user b ON a.id = b.prev_id \r\n              LEFT JOIN k_user c ON b.id = c.prev_id \r\n              LEFT JOIN k_user d ON c.id = d.prev_id\r\n              WHERE d.id={$user_id} AND a.acl = 5";
                break;
            case 3 :
                $sql = "SELECT a.id FROM k_user a \r\n              LEFT JOIN k_user b ON a.id = b.prev_id \r\n              LEFT JOIN k_user c ON b.id = c.prev_id \r\n              WHERE c.id={$user_id} AND a.acl = 5";
                break;
            case 4 :
                $sql = "SELECT a.id FROM k_user a \r\n              LEFT JOIN k_user b ON a.id = b.prev_id \r\n              WHERE b.id={$user_id} AND a.acl = 5";
                break;
            case 5 :
                return $user_id;
            default :
                return false;
        }
        $result = $this->db->query($sql);
        if ( $row = mysql_fetch_array($result , MYSQL_ASSOC) )
        {
            return $row['id'];
        }
        return false;
    }

    public function updateNowRatetoBaseRate($lotto_id)
    {
        $rateTbl = "rate_{$this->tbl}";
        $sql = "UPDATE {$rateTbl} a, {$rateTbl} b SET ";
        $sql .= " a.r00 = b.r00, a.r01 = b.r01, a.r02 = b.r02, a.r03 = b.r03, a.r04 = b.r04";
        $sql .= ", a.r05 = b.r05, a.r06 = b.r06, a.r07 = b.r07, a.r08 = b.r08, a.r09 = b.r09";
        $sql .= ", a.r10 = b.r10, a.r11 = b.r11, a.r12 = b.r12, a.r13 = b.r13, a.r14 = b.r14";
        $sql .= ", a.r15 = b.r15, a.r16 = b.r16, a.r17 = b.r17, a.r18 = b.r18, a.r19 = b.r19";
        $sql .= ", a.r20 = b.r20, a.r21 = b.r21";
        $sql .= " WHERE a.lotto_id >= {$lotto_id} AND b.lotto_id = 0 AND a.bettype = b.bettype AND a.subid = b.subid AND a.disk = b.disk";
        $this->db->query($sql);
        $sql = "DELETE FROM ratenum_{$this->tbl} WHERE lotto_id >= {$lotto_id}";
        $this->db->query($sql);
    }

    public function updateRateSub0toSub12($bettype)
    {
        $rateTbl = "rate_{$this->tbl}";
        $okI = 0;
        $i = 1;
        while ( $i < 3 )
        {
            $fStr = "`lotto_id`, `bettype`, `disk`, `r00`, `r01`, `r02`, `r03`, `r04`, `r05`, `r06`, `r07`, `r08`, `r09`, `r10`, `r11`, `r12`, `r13`, `r14`, `r15`, `r16`, `r17`, `r18`, `r19`, `r20`, `r21`";
            $sql = "INSERT INTO {$rateTbl} ( {$fStr}, `subid` )";
            $sql .= " SELECT {$fStr} , {$i} as `subid` FROM {$rateTbl} AS b";
            $sql .= " WHERE b.lotto_id = 0 AND b.bettype = {$bettype} AND b.subid = 0";
            $sql .= " ON DUPLICATE KEY UPDATE ";
            $sql .= "  r00 = b.r00, r01 = b.r01, r02 = b.r02, r03 = b.r03, r04 = b.r04";
            $sql .= ", r05 = b.r05, r06 = b.r06, r07 = b.r07, r08 = b.r08, r09 = b.r09";
            $sql .= ", r10 = b.r10, r11 = b.r11, r12 = b.r12, r13 = b.r13, r14 = b.r14";
            $sql .= ", r15 = b.r15, r16 = b.r16, r17 = b.r17, r18 = b.r18, r19 = b.r19";
            $sql .= ", r20 = b.r20, r21 = b.r21";
            if ( $this->db->query($sql) )
            {
 ++ $okI;
            }
            ++ $i;
        }
        return $okI;
    }

    public function updateRateSynGametype($is5NFlag = 1)
    {
        global $g_gametype_3d;
        $gamtypeArr = $g_gametype_3d;
        $fStr = "`lotto_id`, `bettype`, `subid`, `disk`, `r00`, `r01`, `r02`, `r03`, `r04`, `r05`, `r06`, `r07`, `r08`, `r09`, `r10`, `r11`, `r12`, `r13`, `r14`, `r15`, `r16`, `r17`, `r18`, `r19`, `r20`, `r21`";
        if ( $this->gametype == 1 || $this->gametype == 2 )
        {
            if ( $this->gametype == 1 )
            {
                $rateTblA = "rate_3t";
                $rateTblB = "rate_3d";
            }
            else
            {
                $rateTblA = "rate_3d";
                $rateTblB = "rate_3t";
            }
            $sql = "INSERT INTO {$rateTblA} ( {$fStr} )";
            $sql .= " SELECT {$fStr} FROM {$rateTblB} AS b";
            $sql .= " WHERE b.lotto_id = 0 ";
            $sql .= " ON DUPLICATE KEY UPDATE ";
            $sql .= "  r00 = b.r00, r01 = b.r01, r02 = b.r02, r03 = b.r03, r04 = b.r04";
            $sql .= ", r05 = b.r05, r06 = b.r06, r07 = b.r07, r08 = b.r08, r09 = b.r09";
            $sql .= ", r10 = b.r10, r11 = b.r11, r12 = b.r12, r13 = b.r13, r14 = b.r14";
            $sql .= ", r15 = b.r15, r16 = b.r16, r17 = b.r17, r18 = b.r18, r19 = b.r19";
            $sql .= ", r20 = b.r20, r21 = b.r21";
            return $this->db->query($sql);
        }
        $rateTblB = "rate_{$this->tbl}";
        $okI = 0;
        if ( $is5NFlag )
        {
            if ( $this->gametype == 10 )
            {
                return false;
            }
            $startI = 11;
            $EndI = 16;
        }
        else
        {
            $startI = 10;
            $EndI = 16;
        }
        for ( $i = $startI; $i < $EndI; $i ++  )
        {
            $rateTblA = "rate_".$gamtypeArr[$i]['en'];
            if ( $i == $this->gametype )
            {
                continue;
            }
            $sql = "INSERT INTO {$rateTblA} ( {$fStr} )";
            $sql .= " SELECT {$fStr} FROM {$rateTblB} AS b";
            $sql .= " WHERE b.lotto_id = 0 ";
            $sql .= " ON DUPLICATE KEY UPDATE ";
            $sql .= "  r00 = b.r00, r01 = b.r01, r02 = b.r02, r03 = b.r03, r04 = b.r04";
            $sql .= ", r05 = b.r05, r06 = b.r06, r07 = b.r07, r08 = b.r08, r09 = b.r09";
            $sql .= ", r10 = b.r10, r11 = b.r11, r12 = b.r12, r13 = b.r13, r14 = b.r14";
            $sql .= ", r15 = b.r15, r16 = b.r16, r17 = b.r17, r18 = b.r18, r19 = b.r19";
            $sql .= ", r20 = b.r20, r21 = b.r21";
            if ( $this->db->query($sql) )
            {
 ++ $okI;
            }
        }
        return $okI;
    }

}

class SRate_3s extends SRate_3d
{

    public function getLotto3DByDate($day)
    {
        $sql = "SELECT * FROM lotto_{$this->tbl} WHERE '".date("Y-m-d H:i:s")."' <= openbet AND open != '0000-00-00' ORDER BY openbet limit 0,1";
        $result = $this->db->query($sql);
        return mysql_fetch_array($result , MYSQL_ASSOC);
    }

}

?>